package caat.application.managedbean;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.faces.component.UIData;
import javax.faces.component.UISelectBoolean;
import caat.application.dao.AdminDAO;
import caat.application.entityobject.AdminEO;
import caat.framework.AppAction;

public class AdminMB extends AppAction {
	private ArrayList<AdminEO> arrAdmin;
	private String username_;
	private String address_;
	private UIData datas;	
	private UISelectBoolean checkbox;
	
	public UIData getDatas() {
		return datas;
	}

	public void setDatas(UIData datas) {
		this.datas = datas;
	}

	public UISelectBoolean getCheckbox() {
		return checkbox;
	}

	public void setCheckbox(UISelectBoolean checkbox) {
		this.checkbox = checkbox;
	}

	public String getUsername_() {
		return username_;
	}

	public void setUsername_(String username_) {
		this.username_ = username_;
	}

	public String getAddress_() {
		return address_;
	}

	public void setAddress_(String address_) {
		this.address_ = address_;
	}

	public ArrayList<AdminEO> getArrAdmin() {
		return arrAdmin;
	}

	public void setArrAdmin(ArrayList<AdminEO> arrAdmin) {
		this.arrAdmin = arrAdmin;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public void refresh() {

		AdminDAO adminDAO = null;
		Connection conn = null;
		StringBuffer sbWhereClause = null;
		Vector params = null;
		try {
			conn = getConnection();
			if (conn != null) {
				// khoi tao cac object
				adminDAO = new AdminDAO(conn);
				sbWhereClause = new StringBuffer();
				params = new Vector();
				// lay ra danh sach Admin
				arrAdmin = (ArrayList<AdminEO>) adminDAO.getAllAdmin(
						sbWhereClause.toString(), params);
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
	// viet 1 ham tai AppAction tra ve 1 List<AdminEO> selectedAdmins - danh sach cac phan tu duoc selected
	public String submit(){
		int size = datas.getRowCount();
		AdminEO selectedRow = new AdminEO();
		List<AdminEO> selectedAdmins = new ArrayList<AdminEO>();
		for(int i = 0; i < size; i++){
			datas.setRowIndex(i);
			if (checkbox.isSelected()) {
	            selectedRow = (AdminEO) datas.getRowData();
	            selectedAdmins.add(selectedRow);
	        }

		}
		return "";
	}
	public String doDelete(){
		return "";
	}
	public String doAdd(){
		return "";
	}
	public String doEdit(){
		return "";
	}
	public AdminMB() {
		super();
		// TODO Auto-generated constructor stub
		refresh();
	}
}
